﻿#region Usings

using System.Collections.Generic;
using System.Windows;
using System.Windows.Interactivity;

#endregion

namespace SilverBox.Extensions
{
    /// <summary>
    /// Interactivity extensions
    /// </summary>
    public static class InteractivityExtensions
    {
        /// <summary>
        /// Filter de bevahiors by the type
        /// </summary>
        /// <typeparam name="T">Type to filter</typeparam>
        /// <param name="items">Behavior Collection to filter</param>
        /// <returns>Behavior Collection filtered</returns>
        public static IEnumerable<T> GetBehaviorsByType<T>(this BehaviorCollection items) where T : Behavior
        {
            var behaviors = new List<T>();

            items.ForEach(b => (b.GetType() == typeof (T)).Do(() => behaviors.Add(b.Cast<T>())));

            return behaviors;
        }

        /// <summary>
        /// Get the Behavior Collection from a Dependency Object
        /// </summary>
        /// <param name="obj">Dependency Object to get the behaviors</param>
        /// <returns>Behavior Collection from the Dependency Object</returns>
        public static BehaviorCollection GetBehaviors(this DependencyObject obj)
        {
            return Interaction.GetBehaviors(obj);
        }
    }
}